#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e18;
int n,c,a[1000010],ans,sum,f1,num,f2,f[1000010],g[1000010],mn[1000010];
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("minimize.in","r",stdin);
	freopen("minimize.out","w",stdout);
	cin>>n>>c;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]<a[i-1])f1=1;
		if(a[i]>100)f2=1;
	}
	if(c==0)cout<<"0";
	else if(f1==0){
		ans=c*n;
		for(int i=1;i<=n;i++){
			num+=a[i];
			sum=(n-i)*c+i*a[i]-num;
			ans=min(ans,sum);
		}
		cout<<ans;
	}
	else if(f2==0&&c<=100){
		ans=inf,mn[101]=inf;
		for(int i=1;i<=n;i++){
			for(int j=0;j<=100;j++){
				if(j<a[i])g[j]=mn[j]+c;
				else g[j]=mn[j]+(j-a[i]);
			}
			for(int j=0;j<=100;j++){
				f[j]=g[j],g[j]=inf;
			}
			for(int j=100;j>=0;j--){
				mn[j]=min(mn[j+1],f[j]);
			}
		}
		for(int i=0;i<=100;i++){
			ans=min(ans,f[i]);
		}
		cout<<ans;
	}
	return 0;
}
/*

*/
